package com.sharding.sphere.demo.algorithm;

import com.google.common.collect.Range;
import lombok.extern.slf4j.Slf4j;
import org.apache.shardingsphere.api.sharding.standard.RangeShardingAlgorithm;
import org.apache.shardingsphere.api.sharding.standard.RangeShardingValue;

import java.util.Arrays;
import java.util.Collection;

/**
 * @author: shuguang.zhang
 * @date : 2021-06-04 15:30
 */
@Slf4j
public class TradeOrderDBRangeShardingAlgorithm implements RangeShardingAlgorithm<Long> {

    @Override
    public Collection<String> doSharding(Collection<String> databaseNames, RangeShardingValue<Long> rangeShardingValue) {

        log.info("TradeOrderDBRangeShardingAlgorithm ---> databaseNames:[{}] complexKeysShardingValue:[{}]", databaseNames, rangeShardingValue);

        Range<Long> valueRange = rangeShardingValue.getValueRange();

        // 范围查询的上限值
        Long upperEndpoint = valueRange.upperEndpoint();

        // 范围查询的下限值
        Long lowerEndpoint = valueRange.lowerEndpoint();

        return Arrays.asList("m1");
    }
}
